package store.swing.order;

import store.domain.OrderItem;
import store.util.AppUtils;

import javax.swing.table.AbstractTableModel;
import java.util.List;

public class OrderItemTableModel extends AbstractTableModel {
    private static final String[] COLUMN_NAMES = {"ID", "ID заказа", "Название товара", "Размер", "Артикул", "Цена", "Кол-во"};
    private static List<OrderItem> orderItems = AppUtils.getService("orderItemService").readAll();

    @Override
    public int getRowCount() {
        return orderItems.size();
    }

    @Override
    public int getColumnCount() {
        return COLUMN_NAMES.length;
    }

    @Override
    public String getColumnName(int column) {
        return COLUMN_NAMES[column];
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0:
                return orderItems.get(rowIndex).getOrderItemId();
            case 1:
                return orderItems.get(rowIndex).getOrderId();
            case 2:
                return orderItems.get(rowIndex).getProductName();
            case 3:
                return orderItems.get(rowIndex).getProductAttributes();
            case 4:
                return orderItems.get(rowIndex).getProductEan();
            case 5:
                return orderItems.get(rowIndex).getProductItemPrice().intValue() + " грн.";
            case 6:
                return orderItems.get(rowIndex).getProductQuantity().intValue();
        }
        return null;
    }
}
